﻿using System;
using System.Collections.Generic;
using Entities;
using System.Data.Common;
using WebLog;
using System.Linq;

namespace Data
{
    public sealed class ReportsData
    {
        /// <summary>
        /// Devuelve la canitdad de usarios de ambos sexos para todas las votaciones
        /// </summary>
        /// <returns> Dictionary<int, string></returns>
        /// 
        public Dictionary<string, int> GetGenericVotinReport(int type, string label,int id)
        {
            //key: description sex value:count
            Dictionary<string, int> dic = new Dictionary<string, int>();

            DataBase bd = new DataBase();
            try
            {
                bd.Connect();
                bd.ProcedureSqlName("REPORTES_GENERICOS");
                bd.AssignInt("@TIPO", type); 
                bd.AssignInt("@id", id); 
                var results = bd.ExecuteDataReader();

                foreach (DbDataRecord row in results)
                {
                    dic.Add(label, row.GetInt32(0));
                }

                results.Close();
                results.Dispose();

            }

            catch (Exception e)
            {
                Logger logger = Logger.GetInstance;
                logger.WriteLog(e);
                dic = null;
            }
            finally
            {
                bd.Disconnect();
                bd.ReleaseResources();
            }

            return dic;
        }


    }
}
